import axios from 'axios'

export const login = ({ username, password }) => {
	return axios.put('/user/signIn', { username, password })
		.then((response) => Promise.resolve(response.data.result))
}

export const getUsers = (page = 1, limit = 20) => {
	return axios.get('/admin/users', { params: { page, limit } })
		.then((response) => Promise.resolve(response.data.result))
}

export const addUser = ({ username, password }) => {
	return axios.post('/admin/user', { username, password })
		.then((response) => Promise.resolve(response.data.result))
}

export const deleteUser = (id) => {
	return axios.delete('/admin/user/' + id)
		.then((response) => Promise.resolve(response.data.result))
}

export const updataUser = ({ id, password }) => {
	return axios.put('/admin/user/' + id + '/password', { password })
		.then((response) => Promise.resolve(response.data.result))
}
